import React, { useState } from 'react';
import Layout from '../components/Layout';
import Banner from '../components/Banner';
import Image from 'next/image';

const ContactPage = () => {
  // 表单状态
  const [formData, setFormData] = useState({
    name: '',
    email: '',
    company: '',
    phone: '',
    subject: '',
    message: ''
  });
  
  // 表单提交状态
  const [formStatus, setFormStatus] = useState<'idle' | 'submitting' | 'success' | 'error'>('idle');
  
  // 表单错误消息
  const [formError, setFormError] = useState('');

  // 处理输入变化
  const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => {
    const { name, value } = e.target;
    setFormData(prev => ({
      ...prev,
      [name]: value
    }));
  };

  // 处理表单提交
  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    setFormStatus('submitting');
    
    // 模拟API请求
    setTimeout(() => {
      // 检查必填字段
      if (!formData.name || !formData.email || !formData.message) {
        setFormStatus('error');
        setFormError('请填写所有必填字段');
        return;
      }
      
      // 表单提交成功
      setFormStatus('success');
      setFormData({
        name: '',
        email: '',
        company: '',
        phone: '',
        subject: '',
        message: ''
      });
    }, 1500);
  };

  // 办公地点数据
  const offices = [
    {
      id: 1,
      city: '广州',
      address: '广州市天河区科技园区8号楼',
      phone: '+86 20 8888 8888',
      email: 'guangzhou@fankexingyue.com',
      image: '/images/offices/guangzhou.jpg'
    }
  ];

  return (
    <Layout title="联系我们 - 凡科星悦" description="与凡科星悦团队取得联系，获取产品信息或技术支持">
      <Banner 
        title="联系我们" 
        subtitle="我们随时准备为您提供帮助，期待与您沟通交流" 
        backgroundImage="/images/contact-banner.jpg"
      />

      {/* 联系表单和信息 */}
      <section className="py-16 bg-white">
        <div className="container mx-auto px-4">
          <div className="flex flex-col md:flex-row">
            {/* 联系表单 */}
            <div className="md:w-2/3 md:pr-12">
              <h2 className="text-3xl font-bold text-gray-800 mb-6">发送消息</h2>
              <p className="text-gray-600 mb-8">
                无论您有任何问题、建议或合作意向，都可以通过以下表单联系我们。我们将在1-2个工作日内回复您。
              </p>

              <form onSubmit={handleSubmit} className="space-y-6">
                <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
                  <div>
                    <label htmlFor="name" className="block text-sm font-medium text-gray-700 mb-1">姓名 <span className="text-red-500">*</span></label>
                    <input
                      type="text"
                      id="name"
                      name="name"
                      value={formData.name}
                      onChange={handleChange}
                      className="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
                      required
                    />
                  </div>
                  <div>
                    <label htmlFor="email" className="block text-sm font-medium text-gray-700 mb-1">邮箱 <span className="text-red-500">*</span></label>
                    <input
                      type="email"
                      id="email"
                      name="email"
                      value={formData.email}
                      onChange={handleChange}
                      className="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
                      required
                    />
                  </div>
                  <div>
                    <label htmlFor="company" className="block text-sm font-medium text-gray-700 mb-1">公司</label>
                    <input
                      type="text"
                      id="company"
                      name="company"
                      value={formData.company}
                      onChange={handleChange}
                      className="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
                    />
                  </div>
                  <div>
                    <label htmlFor="phone" className="block text-sm font-medium text-gray-700 mb-1">电话</label>
                    <input
                      type="tel"
                      id="phone"
                      name="phone"
                      value={formData.phone}
                      onChange={handleChange}
                      className="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
                    />
                  </div>
                </div>

                <div>
                  <label htmlFor="subject" className="block text-sm font-medium text-gray-700 mb-1">主题</label>
                  <select
                    id="subject"
                    name="subject"
                    value={formData.subject}
                    onChange={handleChange}
                    className="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
                  >
                    <option value="">请选择...</option>
                    <option value="product">产品咨询</option>
                    <option value="service">服务咨询</option>
                    <option value="support">技术支持</option>
                    <option value="partnership">合作洽谈</option>
                    <option value="career">招聘咨询</option>
                    <option value="other">其他问题</option>
                  </select>
                </div>

                <div>
                  <label htmlFor="message" className="block text-sm font-medium text-gray-700 mb-1">留言内容 <span className="text-red-500">*</span></label>
                  <textarea
                    id="message"
                    name="message"
                    value={formData.message}
                    onChange={handleChange}
                    rows={6}
                    className="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
                    required
                  ></textarea>
                </div>

                {formStatus === 'error' && (
                  <div className="bg-red-50 text-red-600 p-3 rounded-md">
                    {formError}
                  </div>
                )}

                {formStatus === 'success' && (
                  <div className="bg-green-50 text-green-600 p-3 rounded-md">
                    消息已发送成功！我们将尽快与您联系。
                  </div>
                )}

                <div>
                  <button
                    type="submit"
                    disabled={formStatus === 'submitting'}
                    className={`px-6 py-3 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors duration-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 ${
                      formStatus === 'submitting' ? 'opacity-70 cursor-not-allowed' : ''
                    }`}
                  >
                    {formStatus === 'submitting' ? (
                      <span className="flex items-center justify-center">
                        <svg className="animate-spin -ml-1 mr-2 h-4 w-4 text-white" fill="none" viewBox="0 0 24 24">
                          <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
                          <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
                        </svg>
                        提交中...
                      </span>
                    ) : '发送消息'}
                  </button>
                </div>
              </form>
            </div>

            {/* 联系信息 */}
            <div className="md:w-1/3 mt-12 md:mt-0">
              <div className="bg-gray-50 p-8 rounded-lg">
                <h3 className="text-xl font-bold text-gray-800 mb-6">联系方式</h3>
                
                <div className="space-y-6">
                  <div className="flex items-start">
                    <div className="flex-shrink-0 mt-1">
                      <svg className="h-6 w-6 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path>
                      </svg>
                    </div>
                    <div className="ml-4">
                      <h4 className="text-base font-semibold text-gray-800">电话咨询</h4>
                      <p className="mt-1 text-gray-600">+86 10 8888 8888</p>
                      <p className="mt-1 text-gray-600">周一至周五 9:00-18:00</p>
                    </div>
                  </div>
                  
                  <div className="flex items-start">
                    <div className="flex-shrink-0 mt-1">
                      <svg className="h-6 w-6 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
                      </svg>
                    </div>
                    <div className="ml-4">
                      <h4 className="text-base font-semibold text-gray-800">邮件咨询</h4>
                      <p className="mt-1 text-gray-600">contact@fankexingyue.com</p>
                      <p className="mt-1 text-gray-600">support@fankexingyue.com</p>
                    </div>
                  </div>
                  
                  <div className="flex items-start">
                    <div className="flex-shrink-0 mt-1">
                      <svg className="h-6 w-6 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
                      </svg>
                    </div>
                    <div className="ml-4">
                      <h4 className="text-base font-semibold text-gray-800">总部地址</h4>
                      <p className="mt-1 text-gray-600">
                        广州市天河区科技园区8号楼
                      </p>
                    </div>
                  </div>
                </div>
                
                <div className="mt-8">
                  <h4 className="text-base font-semibold text-gray-800 mb-4">关注我们</h4>
                  <div className="flex space-x-4">
                    <a href="#" className="text-gray-400 hover:text-blue-600 transition-colors duration-300">
                      <span className="sr-only">WeChat</span>
                      <svg className="h-6 w-6" fill="currentColor" viewBox="0 0 24 24">
                        <path d="M8.667 15.373c-.28.476-1.094.952-1.932.952-1.026 0-1.862-.476-1.862-1.428 0-.714.476-1.428 1.332-1.428.952 0 1.666.476 1.666 1.428 0 .074-.01.14-.02.204l-.184.272zm7.46 0c-.28.476-1.094.952-1.932.952-1.026 0-1.862-.476-1.862-1.428 0-.714.476-1.428 1.332-1.428.952 0 1.666.476 1.666 1.428 0 .074-.01.14-.02.204l-.184.272zm-9.812-6.772c.238-.392.784-.784 1.4-.784.784 0 1.428.392 1.428 1.148 0 .56-.392 1.148-1.12 1.148-.728 0-1.414-.392-1.414-1.148 0-.072.01-.122.018-.186l-.312-.178zm6.412 0c.238-.392.784-.784 1.4-.784.784 0 1.428.392 1.428 1.148 0 .56-.392 1.148-1.12 1.148-.728 0-1.414-.392-1.414-1.148 0-.072.01-.122.018-.186l-.312-.178zM12.07 2C5.918 2 1 6.075 1 11.08c0 2.75 1.414 5.223 3.822 6.918 0 0-.42 1.428-1.736 2.92 0 0 2.94-.42 4.725-1.594 1.386.392 2.82.588 4.26.588 6.152 0 11.07-4.074 11.07-8.833C23.14 6.075 18.22 2 12.07 2z" />
                      </svg>
                    </a>
                    <a href="#" className="text-gray-400 hover:text-blue-600 transition-colors duration-300">
                      <span className="sr-only">Weibo</span>
                      <svg className="h-6 w-6" fill="currentColor" viewBox="0 0 24 24">
                        <path d="M10.098 20c-4.038 0-7.798-1.59-7.798-5.42 0-2.472 1.982-5.486 5.103-6.102 1.493-.205 3.462.717 3.093 2.539-.172.307-.613.205-.818.154-1.157-.614-2.095.256-2.095 1.28 0 .87.869 2.094 3.15 2.094 1.5 0 2.508-.563 2.739-1.48.205-.768-.256-1.894-1.588-2.254l.461-1.637s1.85.307 2.457 1.075c.613.717.92 1.688.46 2.815-.512 1.28-2.095 1.944-2.65 2.2-.516.308-.256.513.307.308 0 0 3.354-1.485 3.252-4.76-.063-3.739-4.089-3.483-4.65-3.483-.533 0-3.354-.051-4.753 2.969-1.077 2.334-.43 6.102 3.663 7.536.664.204.307.563-.333.666zm7.96-13.358c.41-.204.178-.87-.332-.87h-1.281c-.256 0-.41.255-.41.511v3.996c0 .307.255.51.41.51h1.281c.279 0 .383-.252.332-.508-.256-1.688.946-3.15 0-3.64zm1.64-.05c.204-.256 0-.82-.408-.82h-1.23c-.256 0-.357.205-.357.46v6.05c0 .256.204.46.356.46h1.23c.26 0 .462-.152.41-.459-.356-2.3 1.282-5.18 0-5.69z" />
                      </svg>
                    </a>
                    <a href="#" className="text-gray-400 hover:text-blue-600 transition-colors duration-300">
                      <span className="sr-only">LinkedIn</span>
                      <svg className="h-6 w-6" fill="currentColor" viewBox="0 0 24 24">
                        <path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.238-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z" />
                      </svg>
                    </a>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>

      {/* 办公地点 */}
      <section className="py-16 bg-gray-50">
        <div className="container mx-auto px-4">
          <h2 className="text-3xl font-bold text-gray-800 mb-10 text-center">全国办公地点</h2>
          
          <div className="grid grid-cols-1 md:grid-cols-3 gap-8">
            {offices.map(office => (
              <div key={office.id} className="bg-white rounded-lg overflow-hidden shadow-md hover:shadow-lg transition-shadow">
                <div className="relative h-48">
                  <Image 
                    src={office.image} 
                    alt={`${office.city}办公室`} 
                    layout="fill" 
                    objectFit="cover" 
                  />
                </div>
                <div className="p-6">
                  <h3 className="text-xl font-bold text-gray-800 mb-3">{office.city}办公室</h3>
                  <div className="space-y-4">
                    <div className="flex items-start">
                      <svg className="h-5 w-5 text-blue-600 mt-0.5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
                      </svg>
                      <span className="text-gray-600">{office.address}</span>
                    </div>
                    <div className="flex items-start">
                      <svg className="h-5 w-5 text-blue-600 mt-0.5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path>
                      </svg>
                      <span className="text-gray-600">{office.phone}</span>
                    </div>
                    <div className="flex items-start">
                      <svg className="h-5 w-5 text-blue-600 mt-0.5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
                      </svg>
                      <span className="text-gray-600">{office.email}</span>
                    </div>
                  </div>
                </div>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* 地图 */}
      <section className="py-16 bg-white">
        <div className="container mx-auto px-4">
          <h2 className="text-3xl font-bold text-gray-800 mb-10 text-center">访问我们</h2>
          
          <div className="relative h-96 rounded-lg overflow-hidden">
            {/* 这里应替换为实际的地图组件，如高德地图、百度地图或谷歌地图 */}
            <div className="absolute inset-0 bg-gray-300 flex items-center justify-center">
              <p className="text-gray-600">此处应显示地图，请集成相应的地图API</p>
            </div>
          </div>
        </div>
      </section>

      {/* FAQ部分 */}
      <section className="py-16 bg-gray-50">
        <div className="container mx-auto px-4">
          <div className="max-w-3xl mx-auto">
            <h2 className="text-3xl font-bold text-gray-800 mb-10 text-center">常见问题</h2>
            
            <div className="space-y-6">
              <div className="bg-white p-6 rounded-lg shadow-md">
                <h3 className="text-lg font-bold text-gray-800 mb-2">如何获取产品演示？</h3>
                <p className="text-gray-600">
                  您可以通过本页面的联系表单或直接发送邮件至contact@fankexingyue.com预约产品演示。
                  我们的销售团队会在1-2个工作日内与您联系，安排合适的时间进行线上或线下演示。
                </p>
              </div>
              
              <div className="bg-white p-6 rounded-lg shadow-md">
                <h3 className="text-lg font-bold text-gray-800 mb-2">如何获取技术支持？</h3>
                <p className="text-gray-600">
                  如果您是我们的客户，可以通过拨打技术支持热线或发送邮件至support@fankexingyue.com获取技术支持。
                  我们的技术支持团队会在工作时间内尽快回复您的问题。
                </p>
              </div>
              
              <div className="bg-white p-6 rounded-lg shadow-md">
                <h3 className="text-lg font-bold text-gray-800 mb-2">是否提供产品培训服务？</h3>
                <p className="text-gray-600">
                  是的，我们为客户提供产品培训服务，包括系统操作、数据分析和系统维护等方面。
                  培训可以根据需要安排线上或线下进行，详情请联系您的客户经理。
                </p>
              </div>
              
              <div className="bg-white p-6 rounded-lg shadow-md">
                <h3 className="text-lg font-bold text-gray-800 mb-2">如何了解产品的最新更新？</h3>
                <p className="text-gray-600">
                  您可以通过订阅我们的电子邮件通讯或关注我们的社交媒体账号，及时获取产品更新和公司动态。
                  此外，我们的官网新闻页面也会定期更新产品信息。
                </p>
              </div>
            </div>
          </div>
        </div>
      </section>
    </Layout>
  );
};

export default ContactPage; 